package com.zhijiang.hospital.controller;

import com.alibaba.excel.EasyExcel;
import com.zhijiang.hospital.entity.dto.PerformanceAssessmentDto;
import com.zhijiang.hospital.service.PerformanceAssessmentService;
import com.zhijiang.util.BaseQuery;
import com.zhijiang.util.Result;
import com.zhijiang.util.TimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_data
 * @description
 * @date 2022-10-26 15:14:54
 */
@Api(tags = "体检绩效考核")
@RestController
@RequestMapping("Performance")
public class PerformanceAssessmentController {
    @Autowired
    PerformanceAssessmentService performanceAssessmentService;

    @ApiOperation("分页查询所有的体检绩效考核")
    @ApiModelProperty(value = "分页查询所有的体检绩效考核")
    @PostMapping("selectAll")
    public Result loadPageList(@RequestBody BaseQuery baseQuery) {
        return Result.ok(performanceAssessmentService.loadPageList(TimeUtil.initBaseQuery(baseQuery)));
    }

    @ApiOperation("体检绩效考核Excel导出数据接口")
    @ApiModelProperty(value = "门诊运行Excel导出数据接口")
    @GetMapping("loadExcel")
    public void loadExcel(HttpServletResponse response) throws IOException {
        List<PerformanceAssessmentDto> list = performanceAssessmentService.findAll();
        String title = "住院运行数据";
        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("体检绩效考核.xlsx", "utf-8"));
        //4. 创建输入、输出流
        EasyExcel.write(response.getOutputStream(), PerformanceAssessmentDto.class).sheet(title).doWrite(list);
    }

    @ApiOperation("体检绩效考核年度数据对比今年")
    @ApiModelProperty(value = "体检绩效考核年度数据对比今年")
    @GetMapping("loadDataYear")
    public Result loadDataYear() {
        return Result.ok(performanceAssessmentService.loadDataYear());
    }

    @ApiOperation("体检绩效考核年度数据对比今年")
    @ApiModelProperty("体检绩效考核年度数据对比今年")
    @GetMapping("loadDataLastYear")
    public Result loadDataLastYear() {
        return Result.ok(performanceAssessmentService.loadDataLastYear());
    }
}
